package logic

import (
	"context"
	"product/model/mysql"

	"product/productrpc/internal/svc"
	"product/productrpc/productrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductShowLogic {
	return &ProductShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品详情
func (l *ProductShowLogic) ProductShow(in *productrpc.ProductShowRequest) (*productrpc.ProductShowResponse, error) {
	// todo: add your logic here and delete this line
	var product mysql.Products
	mysql.DB.Debug().Where("id=?", in.ProductId).Find(&product)

	product.BrowseNumber = product.BrowseNumber + 1

	mysql.DB.Debug().Updates(&product)
	return &productrpc.ProductShowResponse{
		Title:        product.Title,
		UserId:       product.UserId,
		Price:        float32(product.Price),
		BrowseNumber: product.BrowseNumber,
		Image:        product.Image,
		ClassId:      product.ClassId,
	}, nil
}
